﻿namespace AiMoWindows.Server
{
    static class Attentions
    {
        public static string AttentionContent { get; set; } = "";

        static string CurrentAttentionID { get; set; } = "";

        static readonly HashSet<string> ReceivedIDs = new HashSet<string>();

        /// <summary>
        /// Attention格式为 ID + $$$ + 正文
        /// 同一个Attention会在一天之内，给每个用户发送三次。
        /// </summary>
        public static void SetAttention(string attention)
        {
            int index = attention.IndexOf("$$$");
            if (index > 0)
            {
                string ID = attention[..index];
                string content = attention[(index + 3)..];

                if (ReceivedIDs.Contains(ID))
                {
                    //已经有这个Attention了，或者当前正在显示这个Attention
                    //不处理
                }
                else
                {
                    CurrentAttentionID = ID;
                    AttentionContent = content;
                    ReceivedIDs.Add(ID);
                }
            }
        }
        /// <summary>
        /// 看过这个Attention，之后关闭。
        /// 在三次接受信息后，或者再次打开之前，不会看到这个attention
        /// </summary>
        public static void CloseCurrentAttention()
        {
            ReceivedIDs.Add(CurrentAttentionID);
            CurrentAttentionID = "";
            AttentionContent = "";
        }
        public static bool HasAttention => !string.IsNullOrWhiteSpace(AttentionContent);
    }
}
